package base_server

import (
	"context"
	"strings"
	"time"

	"google.golang.org/grpc"
	"jihe.common/protos/base_server/proto"
)

var once = false
var conns []proto.BaseClient

func GetClient() []proto.BaseClient {
	if !once {
		for i := 0; i < len(conf.Get().Grpc.BaseServers); i++ {
			grpcConn, err := grpc.Dial(conf.Get().Grpc.BaseServers[i], grpc.WithInsecure())
			if err != nil {
				return conns
			}
			conns = append(conns, proto.NewBaseClient(grpcConn))
		}
		once = true
	}
	return conns
}

func BaseGetAlgorithmConfig(c context.Context, in *proto.BaseGetAlgorithmConfigReq) (out *proto.BaseAlgorithmConfig, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetAlgorithmConfig(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateAlgorithmConfig(c context.Context, in *proto.BaseAlgorithmConfig) (out *proto.BaseUpdateAlgorithmConfigRes, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateAlgorithmConfig(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseCreateFashion(c context.Context, in *proto.BaseFashion) (out *proto.BaseFashion, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseCreateFashion(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetFashionList(c context.Context, in *proto.BaseGetFashionListReq) (out *proto.BaseGetFashionListRes, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetFashionList(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetFashionDetail(c context.Context, in *proto.BaseGetFashionDetailReq) (out *proto.BaseGetFashionDetailRes, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetFashionDetail(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateFashion(c context.Context, in *proto.BaseFashion) (out *proto.BaseFashion, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateFashion(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateFashionItemObj(c context.Context, in *proto.BaseCutparts) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateFashionItemObj(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateFashionDxf(c context.Context, in *proto.BaseFashion) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateFashionDxf(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateFashionAlgorithmParam(c context.Context, in *proto.BaseFashion) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateFashionAlgorithmParam(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseDeleteCutpart(c context.Context, in *proto.BaseCutpart) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseDeleteCutpart(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetCutpartDetail(c context.Context, in *proto.BaseCutpart) (out *proto.BaseCutpart, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetCutpartDetail(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateCutpart(c context.Context, in *proto.BaseCutpart) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateCutpart(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseCreateFabric(c context.Context, in *proto.BaseFabric) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseCreateFabric(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateFabric(c context.Context, in *proto.BaseFabric) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateFabric(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetDetailFabric(c context.Context, in *proto.BaseFabric) (out *proto.BaseFabric, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetDetailFabric(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetListFabric(c context.Context, in *proto.BaseGetListFabricReq) (out *proto.BaseGetListFabricRes, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetListFabric(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseDeleteFabric(c context.Context, in *proto.BaseFabric) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseDeleteFabric(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

//纹样
func BaseCreatePattern(c context.Context, in *proto.BasePattern) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseCreatePattern(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdatePattern(c context.Context, in *proto.BasePattern) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdatePattern(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetPatternDetail(c context.Context, in *proto.BasePattern) (out *proto.BasePattern, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetPatternDetail(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetPatternList(c context.Context, in *proto.BaseGetPatternListReq) (out *proto.BaseGetPatternListRes, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetPatternList(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseDeletePattern(c context.Context, in *proto.BasePattern) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseDeletePattern(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateCutpartFabric(c context.Context, in *proto.BaseUpdateCutpartFabricReq) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateCutpartFabric(c, in)
		if err != nil && strings.Index(err.Error(), "connection refused") != -1 {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetFashionTypes(c context.Context, in *proto.BaseFashionTypes) (out *proto.BaseFashionTypes, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetFashionTypes(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetRecommendedFashions(c context.Context, in *proto.BaseNull) (out *proto.BaseGetFashionListRes, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetRecommendedFashions(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseDiyPatternCreate(c context.Context, in *proto.BaseDiyPattern) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseDiyPatternCreate(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseDiyPatternList(c context.Context, in *proto.BaseDiyPattern) (out *proto.BaseDiyPatternListRes, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseDiyPatternList(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

//我的作品
func BaseCreateWorksCollection(c context.Context, in *proto.BaseWorksCollectionWorks) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseCreateWorksCollection(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateWorksCollection(c context.Context, in *proto.BaseWorksCollectionWorks) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateWorksCollection(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetWorksCollectionList(c context.Context, in *proto.BaseWorksCollection) (out *proto.BaseWorksCollections, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetWorksCollectionList(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetWorksCollectionDetail(c context.Context, in *proto.BaseWorksCollection) (out *proto.BaseWorksCollectionWorks, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetWorksCollectionDetail(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseDeleteWorksCollection(c context.Context, in *proto.BaseWorksCollection) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseDeleteWorksCollection(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseCreateCustomerRegistration(c context.Context, in *proto.BaseCustomerRegistration) (out *proto.BaseCustomerRegistration, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseCreateCustomerRegistration(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetCustomerRegistrationList(c context.Context, in *proto.BaseGetCustomerRegistrationListReq) (out *proto.BaseGetCustomerRegistrationListRes, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetCustomerRegistrationList(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetFashionListByIds(c context.Context, in *proto.BaseGetFashionListByIdsReq) (out *proto.BaseFashions, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetFashionListByIds(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetCustomerRegistrationDetail(c context.Context, in *proto.BaseCustomerRegistration) (out *proto.BaseCustomerRegistration, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetCustomerRegistrationDetail(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateCustomerRegistration(c context.Context, in *proto.BaseCustomerRegistration) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateCustomerRegistration(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetFashionFabrics(c context.Context, in *proto.BaseGetFashionFabricsReq) (out *proto.BaseFabrics, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetFashionFabrics(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetCutpartByNeedId(c context.Context, in *proto.BaseNeedCutpart) (out *proto.BaseNeedCutparts, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetCutpartByNeedId(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseGetCutpartsByIds(c context.Context, in *proto.BaseGetCutpartsByIdsReq) (out *proto.BaseCutparts, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseGetCutpartsByIds(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateNeedCutpartByCutpartId(c context.Context, in *proto.BaseNeedCutpart) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateNeedCutpartByCutpartId(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseCreateNeedCutpart(c context.Context, in *proto.BaseNeedCutpart) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseCreateNeedCutpart(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseSetRecommendedFashion(c context.Context, in *proto.BaseFashion) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseSetRecommendedFashion(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseFashionOffline(c context.Context, in *proto.BaseFashion) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseFashionOffline(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseDeleteNeedCutpartByNeedId(c context.Context, in *proto.BaseNeedCutpart) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseDeleteNeedCutpartByNeedId(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseUpdateNeedObjByNeedId(c context.Context, in *proto.BaseCustomerRegistration) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseUpdateNeedObjByNeedId(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func BaseFashionDelete(c context.Context, in *proto.BaseFashion) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].BaseFashionDelete(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func HandleUpdateObjUrl(c context.Context, in *proto.HandleUpdateObjUrlReq) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].HandleUpdateObjUrl(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func UpdateBorderPointUrlById(c context.Context, in *proto.UpdateBorderPointUrlByIdReq) (out *proto.BaseNull, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].UpdateBorderPointUrlById(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func GetCutpartList(c context.Context, in *proto.GetCutpartListReq) (out *proto.BaseCutparts, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].GetCutpartList(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func GetStoreByDuid(c context.Context, in *proto.GetStoreByDuidReq) (out *proto.DStore, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].GetStoreByDuid(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func CreateStore(c context.Context, in *proto.DStore) (out *proto.DStore, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].CreateStore(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func CreateStoregroup(c context.Context, in *proto.DStoreGroup) (out *proto.DStoreGroup, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].CreateStoregroup(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func GetStoregroupList(c context.Context, in *proto.GetStoregroupListReq) (out *proto.DStoreGroups, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].GetStoregroupList(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func CreateStoreFashion(c context.Context, in *proto.DStoreFashion) (out *proto.DStoreFashion, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].CreateStoreFashion(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}

func GetStoreGroupFashion(c context.Context, in *proto.GetStoreGroupFashionReq) (out *proto.DStoreFashions, err error) {
	clients := GetClient()
	num := time.Now().UnixNano()
	for i := 0; i < len(clients); i++ {
		index := (num + int64(i)) % int64(len(clients))
		out, err = clients[index].GetStoreGroupFashion(c, in)
		if err != nil && strings.Contains(err.Error(), "connection refused") {
			//fmt.Println(err.Error())
		} else {
			return
		}
	}
	return
}
